#include "HelpSelectDialog.h"
#include "ui_HelpSelectDialog.h"

HelpSelectDialog::HelpSelectDialog(const QMap<QString, QUrl>& map, const QString& topic, QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::HelpSelectDialog),
    map(map)
{
    setModal(true);
    m_ui->setupUi(this);
    QMap<QString, QUrl>::const_iterator it;
    it = map.begin();
    m_ui->label->setText("Choose a topic for: <b>" + topic + "</b>");
    while (it != map.end())
    {
        new QListWidgetItem(it.key(), m_ui->listWidget);
        it++;
    }
}

HelpSelectDialog::~HelpSelectDialog()
{
    delete m_ui;
}

void HelpSelectDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

QUrl HelpSelectDialog::getSelectedUrl()
{
    if (m_ui->listWidget->selectedItems().size() == 1)
        return map.find(m_ui->listWidget->selectedItems()[0]->data(0).toString()).value();
    return QUrl();
}
